<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('子公司数据') }}</span>
    </div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfSubsidiaryDataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人名称')" align="center" prop="gpName">
        <template slot-scope="scope">
          <span class="link-type">{{ scope.row.gpName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金数量')" align="center" prop="fundCount">
        <template slot-scope="scope">
          <span class="link-type">{{ scope.row.fundCount }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否自动同步')" align="center" prop="isAutomaticSynchronization" width="100px" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isAutomaticSynchronization"
            active-value="Y"
            inactive-value="N"
            @change="statusChangeHandle(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="280">
        <template>
          <el-button
            size="small"
            type="text"
          >{{ $t('手动同步') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

export default {
  components: {
  },
  data() {
    return {
      // 填报数据遮罩层
      loading: true,
      // 填报数据总条数
      total: 0,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      formOpen: false,
      // 子公司数据表格数据
      bfSubsidiaryDataList: [],
      // 查询参数
      queryParams: {
        gpName: undefined,
        year: undefined,
        type: undefined,
        status: 'Y',
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询填报数据审核列表 */
    getList() {
      this.loading = true
      this.bfSubsidiaryDataList = [
        {
          id: crypto.randomUUID(),
          gpName: '上海孚腾',
          fundCount: 2,
          isAutomaticSynchronization: 'Y'
        },
        {
          id: crypto.randomUUID(),
          gpName: '中国国新控股',
          fundCount: 3,
          isAutomaticSynchronization: 'Y'
        }
      ]
      this.loading = false
    },
    // 表单重置
    reset() {
      this.form = {
        gpName: undefined,
        fundCount: 0,
        isAutomaticSynchronization: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 删除按钮操作 */
    deleteHandle(row, index) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return true
      }).then(() => {
        this.bfSubsidiaryDataList.splice(index, 1)
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    statusChangeHandle(row) {
      // 原始状态
      const originalStatus = row.isAutomaticSynchronization === 'Y' ? 'N' : 'Y'
      const statusFormat = this.statusFormat(row.isAutomaticSynchronization)
      this.$confirm(this.$t('此操作将 "' + statusFormat + '", 是否继续?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        // 确认后执行状态改变
        return this.msgSuccess(this.$t(statusFormat + '成功'))
      }).catch(() => {
        // 取消后重置状态
        row.isAutomaticSynchronization = originalStatus
      })
    },
    statusFormat(status) {
      return status === 'Y' ? '开启' : '关闭'
    },
    initGpName(val) {
      this.form.gpName = val.name
    },
    submitForm() {
      this.loading = true
      if (this.form.id) {
        // eslint-disable-next-line no-unused-vars
        let accountInfo = this.bfSubsidiaryDataList.find(val => val.id === this.form.id)
        accountInfo = this.form
      } else {
        this.form.id = crypto.randomUUID()
        this.bfSubsidiaryDataList.push(this.form)
      }
      this.loading = false
      this.formOpen = false
    }
  }
}
</script>
